home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Games / MoofWars / Tim's Libraries / TGraphicCollection.h < prev   
Encoding:
C/C++ Source or Header  |  2000-09-28  |  4.5 KB  |  130 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        TGraphicCollection.h
  3.  
  4.     Contains:    See TGraphicCollection.cp for description and the list of changes.
  5.  
  6.     Written by: Timothy Carroll    
  7.  
  8.     Copyright:    Copyright © 1996-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 7/2/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23. #ifndef _TGRAPHICCOLLECTION_
  24. #define _TGRAPHICCOLLECTION_
  25.  
  26. #pragma once
  27.  
  28. #include "TGraphic.h"
  29.  
  30. #if PRAGMA_STRUCT_ALIGN
  31. #pragma options align=power
  32. #endif
  33.  
  34.  
  35. class TGraphicCollection
  36. {
  37.     public:
  38.     
  39. /*****************************************************************************
  40. Static Creator and Reference Counting
  41.  
  42. These are the routines that handle the actual creation of the objects, along
  43. with reference counting and so on.  You don't dispose of an object directly,
  44. you just dispose of your reference.  It will automatically be chucked out
  45. when all references are deleted.
  46.  
  47. A TGraphicCollection is defined by a resource of type 'SptA' or sprite array.
  48. *****************************************************************************/
  49.     static    TGraphicCollection     *NewCollection (SInt16 resID);
  50.  
  51.     void    AddReference (void);
  52.     void    DisposeReference (void);
  53.     
  54.     
  55.     
  56. /*****************************************************************************
  57. Locking and Unlocking
  58.     
  59. You are never required to lock a collection, but you can choose to lock them
  60. down high in memory to ensure that they don't move around when other, critical
  61. memory allocations are being done.
  62. *****************************************************************************/
  63.     OSStatus    LockCollection (void);
  64.     OSStatus    UnlockCollection (void);
  65.     
  66.     
  67. /*****************************************************************************
  68. Creating and destroying the collection
  69.  
  70. The actual work to load by CreateCollection.  DisposeCollection releases any
  71. references to the list of TGraphics and disposes any additional memory we
  72. may have allocated.
  73. *****************************************************************************/
  74.     OSStatus    CreateCollection (void);
  75.     OSStatus    DestroyCollection (void);
  76.     
  77.     
  78. /*****************************************************************************
  79. Accessor Functions
  80.  
  81. We actually do allow a client to obtain a TGraphic directly.  An immediate
  82. link is not made when this is done.  Clients should assume the TGraphic will
  83. be available through the current scope, and if you need it longer than that,
  84. you should explicitly create a reference to it.
  85. *****************************************************************************/
  86.  
  87.     SInt16            GetResID(void) {return fResID;}
  88.     Rect            GetBounds (UInt32 index);
  89.     TGraphic        *GetTGraphic (UInt32 index); // returns a naked TGraphic.  Use sparingly.
  90.     
  91.     
  92. /*****************************************************************************
  93. Utility Functions
  94.  
  95. These just call through to the equivalent TGraphic classes.
  96. *****************************************************************************/
  97.     void            CopyImage (UInt32 index, SInt32 top, SInt32 left, Boolean useBackground);                                   
  98.     Boolean            HitTest (UInt32 index, SInt32 v, SInt32 h);
  99.     
  100.  
  101. protected:
  102.         
  103. /*****************************************************************************
  104. Constructor/Destructor
  105.     
  106. The contructor and destructor are only called internally by the class.  Clients
  107. should ask for an object via its resource ID, using the static routine above.
  108. *****************************************************************************/
  109.     TGraphicCollection (SInt16 resID);
  110.     ~TGraphicCollection (void);
  111.  
  112.     
  113. /*****************************************************************************
  114. Data Structures
  115.     
  116. The actual data used to hold the TGraphicCollection.  The structs could use
  117. either 68K or PowerPC alignment (they come out the same).
  118. *****************************************************************************/
  119.  
  120.     Handle            fGraphics;           // 4 bytes
  121.     SInt16            fResID;            // 2 bytes
  122.     UInt16            fReferenceCount;   // 2 bytes, # of owners of this collection;
  123.     UInt32            fNumberOfGraphics; // 4 bytes
  124. };
  125.  
  126. #if PRAGMA_STRUCT_ALIGN
  127. #pragma options align=reset
  128. #endif
  129.  
  130. #endif /* _TGRAPHICCOLLECTION_ */